package com.ruoyi.common.utils.pack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;

/**
 * 虚拟捆包号生成
 * 
 * @author ruoyi
 */
public class PackUtils
{
    private static final Logger log = LoggerFactory.getLogger(PackUtils.class);

    /**
     * prefix default NL
     * separator divide -/_/''
     * digit Max 32
    */
    public static synchronized String getPackNumber(String prefix, String separator, Integer digit)
    {
        String pack = UUID.randomUUID().toString().toUpperCase().replace("-", "");

        //log.debug("QQQ " + "pack = " + pack);
        StringBuffer sb = new StringBuffer();
        if(prefix != null){
            sb.append(prefix);
        }
        if(separator != null){
            sb.append(separator);
        }
        if(digit <= pack.length() ){
            sb.append(pack.substring(0, digit));
        } else {
            log.debug("error digit = {} > random.length = {}", digit, pack.length());
        }
        //log.debug("QQQ " + "getPackNumber = " + sb.toString());
        return sb.toString();
    }

}
